/**
 *
 */
package nz.ac.massey.jfontview.example;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;

import javax.swing.JFileChooser;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import javax.swing.JTextPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import nz.ac.massey.jfontview.FontList;

/**
 * @author Carl Robinson
 * @version 0.1
 *
 */
public class EditorUI {

	private static JTextPane editor;
	private static FontList favourites;
	public static JFileChooser fc;
	private static JFrame frame;
	/**
	 *Create a new instance of the editor
	 */
	public EditorUI() {

	}

	public void init(){

		frame = new JFrame("Super Duper Java Editor");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		fc = new JFileChooser();
		fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

		//Set up menu bar
		JMenuBar menubar = new JMenuBar();
		JMenu file = new JMenu("File");
		menubar.add(file);
		JMenuItem newdoc = new JMenuItem("New");
		newdoc.setActionCommand("newdoc");
		newdoc.addActionListener(new MenuEvent());
		file.add(newdoc);

		file.add(new JSeparator());
		JMenuItem open = new JMenuItem("Open");
		open.setActionCommand("open");
		open.addActionListener(new MenuEvent());
		file.add(open);

		JMenuItem close = new JMenuItem("Close");
		close.setActionCommand("close");
		close.addActionListener(new MenuEvent());
		file.add(close);
		file.add(new JSeparator());

		JMenuItem save = new JMenuItem("Save");
		save.setActionCommand("save");
		save.addActionListener(new MenuEvent());
		file.add(save);

		JMenuItem saveas = new JMenuItem("Save As");
		saveas.setActionCommand("saveas");
		saveas.addActionListener(new MenuEvent());
		file.add(saveas);
		file.add(new JSeparator());

		JMenuItem exit = new JMenuItem("Exit");
		exit.setActionCommand("exit");
		exit.addActionListener(new MenuEvent());
		file.add(exit);

		JMenu edit = new JMenu("Edit");
		menubar.add(edit);
		JMenuItem editfont = new JMenuItem("Change Font");
		editfont.setActionCommand("editfont");
		editfont.addActionListener(new MenuEvent());
		edit.add(editfont);



		Container contentPane = frame.getContentPane();

		JPanel panel = new JPanel(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();

		editor = new JTextPane();
		editor.setPreferredSize(new Dimension(640,480));
		JScrollPane editorscroll = new JScrollPane(editor);

		c.fill = GridBagConstraints.BOTH;
		c.anchor = GridBagConstraints.FIRST_LINE_START;

		c.weightx = 1.0;
		c.weighty = 1.0;
		c.gridx = 0;
		c.gridy = 0;
		panel.add(editorscroll,c);

		contentPane.add(panel);
		frame.setJMenuBar(menubar);

		frame.pack();
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		frame.setLocation((screenSize.width-frame.getWidth())/2,(screenSize.height-frame.getHeight())/2);
		frame.setVisible(true);
	}

	/**
	 * @return the editor
	 */
	public static JTextPane getEditor() {
		return EditorUI.editor;
	}

	public static JFrame getFrame(){
		return frame;
	}

	/**
	 * @return the favourite fonts
	 */
	public static FontList getFavourites() {
		return EditorUI.favourites;
	}

	/**
	 * @param favs the favourite fonts to set
	 */
	public static void setFavourites(FontList favs) {
		EditorUI.favourites = favs;
	}





}
